//
//  MenuCollectionViewCell_SizeFits.m
//  MKUI
//
//  Created by 苏尚进 on 2020/10/10.
//Copyright © 2020 moon. All rights reserved.
//

#import "MenuCollectionViewCell_SizeFits.h"

@interface MenuCollectionViewCell_SizeFits ()

@end

@implementation MenuCollectionViewCell_SizeFits
- (id)initWithFrame:(CGRect)frame{
	if (self=[super initWithFrame:frame]) {
        self.menuButton = [[MKUIFlowLayoutButton alloc] initWithContentStyle:MKUIFlowLayoutButtonContentStyleHorizontal];
        self.menuButton.contentInsets = MKUIEdgeInsetsMakeSameEdge(5);
        [self.menuButton setTitleColor:[UIColor systemBlueColor] forState:UIControlStateNormal];
        self.menuButton.titleLabel.numberOfLines = 0;
        self.menuButton.imageSize = CGSizeMake(80, 80);
        self.menuButton.interitemSpacing = 10;
        self.menuButton.hideImageViewForNoImage = YES;
        [self.menuButton addTarget:self action:@selector(_menuButtonDidTap:) forControlEvents:UIControlEventTouchUpInside];
        self.menuButton.userInteractionEnabled = NO;
        [self.contentView addSubview:self.menuButton];
	}
	return self;
}
- (void)_menuButtonDidTap:(id)sender{
    [self.collectionCellModel didClickSelf];
}
- (void)layoutSubviews{
    [super layoutSubviews];
    CGRect bounds = self.contentView.bounds;
    self.menuButton.frame = bounds;
}
- (void)setCollectionCellModel:(__kindof MKUICollectionViewCellModel *)collectionCellModel{
    [super setCollectionCellModel:collectionCellModel];
    Menu *menu = self.collectionCellModel.modelValue;
    if(!menu){
        return;
    }
    [self.menuButton setImage:menu.icon forState:UIControlStateNormal];
    [self.menuButton setTitle:[NSString stringWithFormat:@"%@(%@-%@)",menu.title,@(self.collectionCellModel.indexPathInModel.section),@(self.collectionCellModel.indexPathInModel.item)] forState:UIControlStateNormal];
}
- (CGSize)sizeThatFits:(CGSize)size{
    CGSize s = [self.menuButton sizeThatFits:size];
    return s;
}
MKDEF_SINGLETON(MenuCollectionViewCell_SizeFits);
#pragma mark - protocol:MKUICollectionViewCellProtocol
//MKDEF_SINGLETON(MenuCollectionViewCell_SizeFits)//动态尺寸
//+ (CGSize)sizeWithCollectionView:(UICollectionView *)collectionView collectionCellModel:(MKUICollectionViewCellModel *)collectionCellModel{
//	return [self dynamicSizeWithCollectionView:collectionView collectionCellModel:collectionCellModel cellShareInstance:[self sharedInstance] calBlock:^CGSize(UICollectionView *collectionView, MKUICollectionViewCellModel *cellModel, MenuCollectionViewCell_SizeFits *cell) {
//		CGSize size = CGSizeMake(44, 44);
//		return size;
//	}];
//}
//+ (CGSize)sizeWithCollectionView:(UICollectionView *)collectionView collectionCellModel:(MKUICollectionViewCellModel *)collectionCellModel{//静态尺寸
//	return CGSizeMake(44, 44);
//}
@end
